package drg_group.suzhou_2023.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.suzhou_2023.Base;
import drg_group.suzhou_2023.MedicalRecord;
import drg_group.suzhou_2023.ADRG.*;

public class MDCN{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"N76.802","N89.700","N94.000","N80.603","N84.301","C79.800x222","N90.501","N91.200x002","N97.200x001","N70.900x003","N70.001","N90.806","N80.301","N84.001","D17.300x003","N94.500","N98.900","Q85.900x047","N83.811","N89.100","N80.602","D39.709","N95.800","S38.200x001","Q52.400x007","N85.816","N70.104","N73.003","N92.401","D25.200x002","N81.301","N82.300","N76.400","N83.800x015","C57.301","N85.810","N85.600","N88.807","N85.001","Q50.000x011","T28.800x001","E28.200","N85.200","Q51.800x007","D28.200x003","A18.100x019+N77.1*","N80.809","Q52.703","N95.201","I77.009","R87.800","N76.301","N82.401","N85.404","N94.806","N85.801","N92.101","N82.200","N82.501","N90.400","C57.800x005","S38.200x006","D39.000x002","R93.800x006","A18.100x026+N74.1*","T28.800x002","N83.500x007","N81.202","E30.900","N88.400","D07.303","N76.000x001","C57.300","A18.115+N74.1*","N87.101","N90.800x024","C79.800x219","N82.301","N99.800x003","N95.300x001","D25.200","N73.605","Q52.901","Q51.801","I89.800x032","C48.100x006","C51.001","D26.702","N93.801","N85.901","E28.800x002","T83.303","N76.500","C79.800x218","N73.501","N92.100x001","N81.203","N91.500","D39.000x001","N81.803","N98.000","N76.000x003","D25.901","R93.803","N90.809","N82.102","A54.004","C76.307","T28.300x003","A56.100x004+N74.4*","N81.800x005","Q85.900x045","C54.100","N83.401","N82.103","I86.300","A54.005","D39.101","N88.102","S39.901","B26.800x009+N74.8*","N80.601","A54.003","D39.005","N87.200x001","N89.810","N75.801","N80.807","Q51.804","S30.200x007","N90.404","N90.601","N81.602","D25.900","N71.101","N97.101","Z52.800x001","C57.701","N91.400","N73.602","N94.802","T28.300x001","N88.806","R87.600","C54.001","T83.305","N83.800x016","N83.800x013","N85.806","N85.809","N73.604","C79.800x223","R87.000","N89.200","A56.101+N74.4*","N90.800x025","N80.800x010","T19.202","D28.100","D39.204","N80.800x011","Q51.805","N85.803","N90.810","N93.900","Q50.302","N85.100","Q27.814","D26.700","D39.707","N90.901","N95.200","Q52.000","N73.801","N87.002","N76.100x001","N80.200","A54.102","S37.601","N88.000","D28.204","N82.900","C79.800x206","Q56.000","N89.600x002","N72.x00x003","D28.900","C55.x00","N80.806","L29.200","N80.804","N83.700","N70.905","S37.810","N76.801","N89.101","D39.705","N85.300x001","Q52.702","N83.500x004","E28.300x002","D25.100x001","N76.000x006","N80.808","N97.100x003","Q52.101","N89.808","N81.601","S37.510","D07.302","D39.200x001","Q52.104","R87.300","N83.503","N92.601","C51.100","C57.700","N85.800x003","C53.100","C79.833","N90.800x011","N80.401","Z31.000x001","N89.400","C79.800x211","D39.703","N94.200","N75.802","T28.800x003","N83.601","N89.600","D28.203","N90.403","N83.207","D25.000x002","N99.800x007","C77.500x003","Q52.700x003","N90.302","S31.400x001","D39.700x001","N94.803","N90.500","N98.100","Q51.900","N76.201","C57.200","N90.301","C79.822","N76.100x002","N89.803","N81.100","C54.900","C79.800x202","N90.811","D28.200x002","N90.805","Q50.502","S37.610","N76.601","C51.200","E28.300x005","S37.410","N83.812","D25.900x001","N92.300","Z01.400x001","N80.300","Z31.201","D28.206","E28.100","D18.000x856","N81.201","N83.800x021","Q50.000","D48.127","N80.100x001","N83.206","Q50.504","Q52.404","N80.302","D18.000x853","D17.700x024","D26.900","N70.902","D07.200","N91.000","N75.100","Q52.601","Q51.202","N84.300","N76.000x004","N70.906","Q50.600x904","Q56.200","Q52.700x004","N73.002","D25.100x002","N86.x02","N70.901","N70.103","N71.900x001","D39.001","N82.801","Q50.601","N90.101","C57.000","N92.000x001","C45.100","Q50.503","N85.808","R93.800x007","C79.824","N73.800x002","S38.200x002","A54.201+N74.3*","N76.101","N83.804","Q52.402","N86.x00x004","N71.902","A18.100x024+N74.1*","C58.x00","Q51.901","Q51.001","Q51.600","S37.600","N73.600","N70.102","S31.400x003","E28.900","A18.100x030+N77.0*","D39.002","N90.801","C79.814","B37.301+N77.1*","N85.812","C51.900","R87.200","A18.102","N81.500","C79.800x213","N85.815","Q50.600","N97.100x001","N92.400","Q51.100x001","N95.100","N82.000","N70.900x007","N87.001","C57.800x004","N88.805","N76.600","N70.002","N89.300","N83.300x001","C79.600","S37.602","D39.706","D06.700","Q50.303","N81.900","D26.100","N90.200","N99.200","C57.400","N85.600x001","C51.000","C57.801","I86.200","N88.804","N73.203","N90.800x009","C46.700x001","C79.800x209","N83.807","R87.100","C79.823","N70.903","N80.200x001","N94.805","N94.807","N89.801","Q52.800x004","N99.201","E28.300x008","S31.400x002","Z31.100","N89.001","N88.803","Q85.900x016","N92.400x003","N90.300","N80.001","S30.200x010","N90.001","Q51.502","S37.710","Q51.400","N97.300","N88.800x010","N90.600","N93.000x001","N91.100","Q51.803","N85.805","S31.401","A54.200x004+N74.3*","N73.104","Z01.800x003","A56.003","N84.000","C57.900","N32.004","N83.100x003","N99.801","D39.902","I89.800x033","N85.000x002","N88.808","D28.000","N95.000","Q50.000x021","N88.200x001","D39.201","N73.201","D39.700x002","N83.101","Q50.100","Q52.408","N83.803","N81.801","A18.113+N74.1*","N85.811","N83.502","N80.805","N88.801","B37.300x002+N77.1*","N90.802","N80.100","N97.901","N89.600x001","N98.300","Q50.300x101","N84.900","N81.300","D26.000","C51.800","N81.400","Q51.201","Q52.300","D07.301","T83.400","N92.200","A18.114+N74.1*","C79.812","A18.100x032","N70.101","N89.806","S31.402","D39.704","N94.900","Q56.400","N81.500x003","I89.000x018","C56.x00x003","D39.003","N92.500","E28.000","N83.902","N76.401","C53.900","N99.300","A18.112+N74.0*","C54.000","N89.809","N90.902","N70.000","N94.600","N81.200","N81.000","N89.807","N92.400x004","D39.200x002","N85.400","N92.000x002","N90.700","Q52.405","D39.901","S37.400","N71.901","T83.400x001","T83.301","D18.000x854","N81.600","Q56.300","B37.300+N77.1*","N73.300","D28.700x001","N82.101","N88.300","N95.101","E89.400x001","N87.900","N97.900","D25.000","Q50.400","C79.800x215","D39.710","N99.800x005","D18.000x824","N89.601","N90.800x010","N90.808","N73.500","N83.102","N82.500","T83.304","D27.x00","R87.700","D39.100x001","C79.800x205","N73.600x006","C53.801","D06.900","N83.300x002","N97.000x001","N73.001","N83.809","N85.002","A59.002+N77.1*","C57.300x001","D26.701","D28.201","N85.000x004","Q50.401","N72.x02","S30.207","C56.x00","N80.600","N90.402","N85.402","D06.000","N80.800x007","Q52.500x001","E89.400x002","N85.401","N72.x00x006","N94.800x009","A51.400x009+N74.2*","N83.901","Q52.103","E89.401","Q51.000","N85.300","N94.804","N70.904","C54.800","N75.900","N97.200x002","N88.802","N73.601","A56.004","N90.800x012","N89.805","N73.400","N88.201","D06.900x002","T19.300x001","R87.400","N89.811","N83.504","N87.901","N89.502","N83.806","I89.000x019","C57.702","N89.800x009","N90.807","Q50.301","T28.300x002","D28.205","N90.701","C79.800x228","N70.900","N76.300x001","N80.900","N94.808","Q51.808","N71.002","N73.101","N81.500x002","D39.100x003","D39.900x001","Z31.300x001","B37.302+N77.1*","N97.400x001","C79.800x216","D07.100x002","N90.100","N71.102","N83.600","E28.301","C53.000","C79.800x220","C54.200","N87.100","N83.808","N80.501","E28.303","N85.813","Z31.300x002","D07.200x002","N80.803","N73.902","N83.001","Z31.200x003","D27.x01","N91.200","N80.802","N96.x00","Q51.203","N85.500","N85.802","N73.103","N92.400x001","A56.100x003+N74.4*","D07.000","Q27.813","C58.x00x003","Q52.200","N80.500","N82.902","Q51.800x012","N88.100","C52.x00","N83.201","N90.401","N84.200","N99.800x010","Q52.407","N90.804","N94.100","D07.304","D39.203","N83.100x002","N93.901","N73.202","N88.900","N85.101","N80.801","N89.000","N99.807","A56.002","S30.200x008","Q50.501","E28.300x001","N82.303","N83.203","N83.202","N80.000","Q52.403","N89.901","C79.800x214","N83.802","D06.100","D39.202","N82.901","N98.800","N83.800x017","D26.100x002","N95.900x001","Q52.700x005","N83.000x002","C57.000x002","N73.606","S39.902","N82.502","T19.201","N94.300","N75.000","D39.701","N97.801","S37.600x002","N84.302","N90.803","C57.101","D39.903","N83.801","E28.200x003","M35.202+N77.8*","N86.x01","Q27.816","S37.500","Z31.200","N90.000","C53.800","A56.104+N74.4*","A60.000x003+N77.1*","N76.200","N91.300","Q51.800x011","N96.x00x003","N71.001","N94.400","N85.403","N97.902","N83.810","E28.302","N72.x03","N72.x01","N98.200","A18.111+N74.1*","N84.100","Q52.400x006","D20.103","N83.204","N83.205","N81.102","T83.302","N83.501","N81.800x004","D28.000x002","N76.000","Q51.300","N89.804","C57.100","N89.802","Q51.806","N83.903","D39.004","Q51.501","N85.700","D39.708","N83.800x012","C57.802","N76.001","Q52.701","N80.303","N96.x00x002","N83.000","N82.900x003","D18.000x817","N83.100","N85.804","N87.000","N89.503","N97.400x002","C57.803","N97.800x004","Q51.802","C58.x00x002","C79.821","Q52.401","N70.100","N85.807","N73.102","D28.202","N83.805","N85.000","N84.800x002","N92.600","Q52.406","D39.702","N81.101","N82.100x001","Q51.100","N73.603","N89.501","Q50.603","N88.101","Q50.600x903","N85.814","Q50.602","N73.903","R87.500","Q50.200","Q51.000x001","C54.300","C79.813","N85.003","D07.100","N81.802"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]) && record.gender!=null && record.gender.equals("2"))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCN入组条件，匹配规则：主诊断匹配、女性");
        String result;

        result=NA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NA2.group(record);
        if (result.length()>0){
            return result;
        }

        result=NB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ND1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NE1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NF1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NG1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (record.ssList!=null && record.ssList.length>0 && Base.contains(Base.SS_VALID,record.ssList[0])){
            Base.groupMessages.putMessage(record.Index,"符合NQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "NQY";
        }

        result=NR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCN的ADRG入组条件");
        return "";
    }
}

